
package com.insigma.business.qrcode.common.converter;


import com.insigma.business.qrcode.intell.dto.UserBSearcher;
import com.insigma.business.qrcode.intell.dto.UserDTO;
import com.insigma.business.qrcode.intell.dto.UserSearchRequest;
import com.insigma.business.qrcode.intell.entity.UserDO;
import org.springframework.beans.BeanUtils;

import java.util.List;


public class UserProviderConverter extends AbstractConverter<UserDTO, UserDO> {

    private final static UserProviderConverter userConverter = new UserProviderConverter();

    private UserProviderConverter(){}

    
    public static UserBSearcher convertRequestSO2Searcher(final UserSearchRequest request){
        final UserBSearcher userBSearcher = new UserBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,userBSearcher);
        return userBSearcher;
    }

    public static List<UserDTO> convertResponseDOList2DTOList(final List<UserDO> userDOList){
        return userConverter.convertGenericResponseDOList2DTOList(userDOList);
    }

    
    public static UserDTO convertResponseDO2DTO(final UserDO userDO){
        return userConverter.convertGenericResponseDO2DTO(userDO);
    }

    
    @Override
    protected UserDTO doConvertResponseDO2DTO(UserDO userDO) {
        final UserDTO userDTO = new UserDTO();
        try {
            BeanUtils.copyProperties(userDO, userDTO);
        }catch(RuntimeException be){
            
            return null;
        }
        return userDTO;
    }

}
